package com.chenfan.mcn.enums;

import com.chenfan.common.extension.dict.DictTranslator;

import java.util.Objects;

/**
 * @Author liuyang
 * @Date 2021/2/5
 * @Time 18:40
 * @Version V1.0
 **/
public enum YearStatusEnum implements DictTranslator<Integer, String> {
    /**
     * 年框合同 状态
     */
    UN_COMMIT(0, "待提交"),

    APPROVAL(1, "审批中"),

    PASSED(2, "审批通过"),

    REJECTED(3, "审批拒绝"),

    CANCEL(4, "已撤回"),

    INVALID(5, "已作废");

    private final Integer code;
    private final String statusName;

    YearStatusEnum(int code, String statusName) {
        this.code = code;
        this.statusName = statusName;
    }

    public int code() {
        return this.code.intValue();
    }

    public static String getStatusName(int code) {
        for (YearStatusEnum status : YearStatusEnum.values()) {
            if (status.code == code) {
                return status.statusName;
            }
        }
        return null;
    }

    /**
     * 根据code获取 枚举
     * @param code
     * @return
     */
    public static YearStatusEnum toEnum(Integer code) {
        if(Objects.isNull(code)) {
            return null;
        }
        YearStatusEnum statusEnum = null;
        for (YearStatusEnum item : YearStatusEnum.values()) {
            if (item.code() == code.intValue()) {
                statusEnum = item;
                break;
            }
        }
        return statusEnum;
    }

    @Override
    public String translate(Integer code) {
        YearStatusEnum yearStatusEnum = YearStatusEnum.toEnum(code);
        return yearStatusEnum != null ? yearStatusEnum.statusName : null;
    }
}
